package com.mostromas.ess.product.controller;

import com.mostromas.ess.entities.ProductSizeType;
import com.mostromas.ess.product.service.IProductSizeTypeService;
import com.mostromas.ess.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 商品尺码分类表-前端控制器
 */
@Api(value = "商品尺码分类管理接口",description = "商品尺码分类管理接口，提供尺码分类的增、删、改、查")
@RestController //所有方法都会返回json字符串进行相应
@RequestMapping("/size_type")
public class ProductSizeTypeController {

    @Autowired
    private IProductSizeTypeService productSizeTypeService;

    /**
     * 获取所有商品尺码分类信息
     * @return
     *
     */
    @PreAuthorize(("hasAuthority('size_type:search')"))
    @ApiOperation("获取商品尺码分类列表接口")
    @GetMapping("/list") //请求路径： /product/size_type/list
    public Result list(){
        return productSizeTypeService.selectAll();
    }

    @PreAuthorize(("hasAuthority('size_type:search')"))
    @ApiOperation("查询商品尺码分类详情接口")
    @ApiImplicitParam(name = "id",value = "分类ID",required = true)
    @GetMapping("/{id}") //请求路径：/product/size_type/{id}
    public Result view(@PathVariable("id") String id){
        ProductSizeType productSizeType = productSizeTypeService.getById(id);
        return Result.ok(productSizeType);
    }

    @PreAuthorize(("hasAuthority('size_type:edit')"))
    @ApiOperation("修改商品尺码分类信息接口")
    @PutMapping //put方式调用接口：/product/size_type
    public Result update(@RequestBody ProductSizeType productSizeType){
        productSizeTypeService.updateById(productSizeType);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('size_type:add')"))
    @ApiOperation("新增商品尺码分类信息接口")
    @PostMapping //post方式调用接口：/product/size_type
    public Result save(@RequestBody ProductSizeType productSizeType){
        productSizeTypeService.save(productSizeType);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('size_type:delete')"))
    @ApiOperation("删除商品尺码分类信息接口")
    @ApiImplicitParam(name = "id",value = "类别ID",required = true)
    @DeleteMapping("/{id}") //delete方式调用接口：/product/size_type/{id}
    public Result delete(@PathVariable("id") String id){
        productSizeTypeService.removeById(id);
        return Result.ok();
    }
}
